What is meant by lambda function in python?Give suitable example.
What is meant by lambda function in python?
517
28-Mar-2023
Krishnapriya Rajeev
30-Mar-2023In Python, a lambda function is a nameless function that can have arguments of any number. It is defined with a single expression that is evaluated and the result returned when the function is called.
Syntax:
Example:
Lambda functions are used when a small function is needed temporarily, and defining a complete function is not necessary. They are also useful as arguments for higher-order functions like map(), filter(), and reduce(). The lambda function takes a list of arguments separated by commas, and the expression is the code that gets executed when the function is called.
For example, here is a lambda function that takes two arguments and returns their sum:
This lambda function can be called like any other function: